package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.TO.ProjectPageQuery;
import com.yegs.jltqc.VO.Project;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @PostMapping("/save")
    public Msg save(@RequestBody Project project){
        try{
            return Msg.success("data",projectService.save(project));
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",projectService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data",projectService.get(id));
    }
    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id){
        return Msg.success("data",projectService.getLast(id));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id){
        return Msg.success("data",projectService.getNext(id));
    }

    @GetMapping("/getByCInvCode")
    public Msg getByCInvCode(@RequestParam String cinvcode){
        return Msg.success("data",projectService.getByCInvCode(cinvcode));
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        projectService.del(id);
        return Msg.success();
    }
    @PostMapping("/query")
    public Msg query(@RequestBody ProjectPageQuery query){
        return Msg.success("page",projectService.query(query));
    }




}
